Skip to content

Create rule S7524 async for should be used with asynchronous iterators in async functions #5116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Jun 5, 2025

You can preview this rule here (updated a few minutes after each push).

Review

A dedicated reviewer checked the rule description successfully for:

  • logical errors and incorrect information
  • information gaps and missing content
  • text style and tone
  • PR summary and labels follow the guidelines

@ghislainpiot ghislainpiot force-pushed the rule/add-RSPEC-S7524 branch from 2a099cc to 2b398e9 Compare June 6, 2025 07:27
@ghislainpiot ghislainpiot changed the title Create rule S7524 Create rule S7524 async for should be used with asynchronous iterators in async functions Jun 6, 2025
@ghislainpiot ghislainpiot marked this pull request as ready for review June 6, 2025 07:57
Copy link
Contributor

@guillaume-dequenne guillaume-dequenne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the overall message of the rule, to me we should be very close to S7515.

@@ -0,0 +1,112 @@
This rule raises an issue when a synchronous `for` loop is used with an iterator implementing both synchronous and asynchronous iteration protocols.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused why here (and throughout the rule description), we are focusing on iterators implementing both sync/async protocols.
I kind of expected a similar wording as S7515, where the message would be "if the iterator is async and we're in an async function, you should use the async protocol", no matter whether both protocols are implemented or not.

Here it seems we are saying that async for should be used even outside of async functions, which doesn't feel right (to be fair, we mention async functions in the "How to fix it" tab, but it's a bit late IMO).


=== Message

Use 'async for' to iterate over dual-protocol iterators in 'async' functions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to focus on dual protocol iterators as well?
I guess using a simple for on an async iterator in an async function should be enough to raise, no? No need to ensure the iterator is dual? (I guess the "dual" part might influence whether we have a bug or a code smell, but that's it?).

@ghislainpiot
Copy link
Contributor

I have reworded closer to S7515

Copy link
Contributor

@joke1196 joke1196 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I have just added a small comment on the severity

"tags": [
"async"
],
"defaultSeverity": "Major",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think with Low the severity should be Minor

Copy link

Quality Gate passed Quality Gate passed for 'rspec-tools'

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
0 Dependency risks
No data about Coverage
No data about Duplication

See analysis details on SonarQube

Copy link

Quality Gate passed Quality Gate passed for 'rspec-frontend'

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
0 Dependency risks
No data about Coverage
No data about Duplication

See analysis details on SonarQube

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants